package com.zl.gmadmin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zl.gmadmin.entity.SysJob;
import com.zl.gmadmin.mapper.SysJobMapper;
import com.zl.gmadmin.service.SysJobService;
import com.zl.gmadmin.utils.Builder;
import com.zl.gmadmin.vo.SelectVo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangliang
 * @version 1.0
 * @date 2021/3/22 10:23
 */
@Service
public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> implements SysJobService {


    private final SysJobMapper sysJobMapper;

    public SysJobServiceImpl(SysJobMapper sysJobMapper) {
        this.sysJobMapper = sysJobMapper;
    }

    @Override
    public List<SelectVo> findAllJobsName() {
        List<SysJob> sysJobs = sysJobMapper.findAll();
        List<SelectVo> jobVos = new ArrayList<>();
        sysJobs.forEach(sysJob -> {
            SelectVo selectVo = Builder.of(SelectVo::new).with(SelectVo::setLabel, sysJob.getName())
                    .with(SelectVo::setEnabled, sysJob.getEnabled().equals("1") ? false :true)
                    .with(SelectVo::setId,sysJob.getId())
                    .build();

            jobVos.add(selectVo);

        });
        return jobVos;
    }
}
